package com.sike.netty.im.server.service;

import java.util.HashMap;
import java.util.Map;

/**
 * 用户信息缓存
 *
 * @author chenssy
 * @date 2023/09/15
 */

public class UserInfoCache {
    public static Map<String,UserInfoDTO> userInfoMap = new HashMap<>();

    static {
        userInfoMap.put("zhangsan",new UserInfoDTO("10001","zhangsan","123456"));
        userInfoMap.put("lisi",new UserInfoDTO("10002","lisi","123456"));
        userInfoMap.put("wangwu",new UserInfoDTO("10003","wangwu","123456"));
        userInfoMap.put("LiLi",new UserInfoDTO("10004","LiLi","123456"));
        userInfoMap.put("zhangwei",new UserInfoDTO("10005","zhangwei","123456"));
        userInfoMap.put("ligang",new UserInfoDTO("10006","ligang","123456"));
        userInfoMap.put("liuyang",new UserInfoDTO("10007","liuyang","123456"));
        userInfoMap.put("chenjing",new UserInfoDTO("10008","chenjing","123456"));
        userInfoMap.put("zhougang",new UserInfoDTO("10009","zhougang","123456"));
        userInfoMap.put("sunfei",new UserInfoDTO("10010","sunfei","123456"));
    }


    /**
     * 获取用户信息
     *
     * @param userName 用户名
     * @return boolean
     */
    public static UserInfoDTO getUserInfoByUserName(String userName) {
        return userInfoMap.get(userName);
    }

    public static UserInfoDTO getUserInfoByUserId(String userId) {
        return userInfoMap.values().stream()
                .filter(x -> userId.equals(x.getUserId()))
                .findFirst().get();
    }
}
